/*
 * Copyright (c) 2015. kupat Corporation. All rights reserved.
 *  see statement on http://www.kupat.cn.
 */
package com.kfgj.hkp.common.utils;



import com.kfgj.hkp.common.exception.ExceptionEvent;
import com.kfgj.hkp.common.exception.IllegalArgsException;

import java.util.Collection;
import java.util.Map;

/**
 * Created by liwensihan on 2014/11/27.
 *
 * @author liwensihan
 */
public class ValidateUtils {

    public static <T> T notNull(T object,String codeOrMsg) {
        if (object == null){
            throw new IllegalArgsException(codeOrMsg);
        }
        return object;
    }
    public static <T> T notNull(T object, ExceptionEvent event) {
        if (object == null){
            throw new IllegalArgsException(event);
        }
        return object;
    }

    public static <T> T notNull(T object, String code,String message) {
        if (object == null) {
            throw new IllegalArgsException(code,message);
        }
        return object;
    }

    public static <T> T notNull(T object, String code,String[] args) {
        if (object == null) {
            throw new IllegalArgsException(code,args);
        }
        return object;
    }

    public static <T> T[] notEmpty(T[] array, String code, String message) {
        if (array == null || array.length == 0) {
            throw new IllegalArgsException(code,message);
        }
        return array;
    }

    public static <T> T[] notEmpty(T[] array, String code, String[] args) {
        if (array == null || array.length == 0) {
            throw new IllegalArgsException(code,args);
        }
        return array;
    }

    public static <T> T[] notEmpty(T[] array, ExceptionEvent event) {
        if (array == null || array.length == 0) {
            throw new IllegalArgsException(event);
        }
        return array;
    }
    public static <T> T[] notEmpty(T[] array, String codeOrMsg) {
        if (array == null || array.length == 0) {
            throw new IllegalArgsException(codeOrMsg);
        }
        return array;
    }

    public static <T extends  Collection<?>> T notEmpty(T collection, String code, String message) {
        if (collection == null || collection.size() == 0) {
            throw new IllegalArgsException(code,message);
        }
        return collection;
    }
    public static <T extends  Collection<?>> T notEmpty(T collection, String codeOrMsg) {
        if (collection == null || collection.size() == 0) {
            throw new IllegalArgsException(codeOrMsg);
        }
        return collection;
    }

    public static <T extends  Collection<?>> T notEmpty(T collection, String code, String[] args) {
        if (collection == null || collection.size() == 0) {
            throw new IllegalArgsException(code,args);
        }
        return collection;
    }

    public static <T extends Collection<?>> T notEmpty(T collection, ExceptionEvent event) {
        if (collection == null || collection.size() == 0) {
            throw new IllegalArgsException(event);
        }
        return collection;
    }


    public static <T extends  Map<?,?>> T notEmpty(T map, String code, String message) {
        if (map == null || map.size() == 0) {
            throw new IllegalArgsException(code,message);
        }
        return map;
    }

    public static <T extends  Map<?,?>> T notEmpty(T map, String code, String[] args) {
        if (map == null || map.size() == 0) {
            throw new IllegalArgsException(code,args);
        }
        return map;
    }

    public static <T extends Map<?,?>> T notEmpty(T map, ExceptionEvent event) {
        if (map == null || map.size() == 0) {
            throw new IllegalArgsException(event);
        }
        return map;
    }

    public static <T extends  CharSequence> T notEmpty(T chars, String code, String message) {
        if (chars == null || chars.length() == 0) {
            throw new IllegalArgsException(code,message);
        }
        return chars;
    }

    public static <T extends  CharSequence> T notEmpty(T chars, String code, String[] args) {
        if (chars == null || chars.length() == 0) {
            throw new IllegalArgsException(code,args);
        }
        return chars;
    }

    public static <T extends CharSequence> T notEmpty(T chars, ExceptionEvent event) {
        if (chars == null || chars.length() == 0) {
            throw new IllegalArgsException(event);
        }
        return chars;
    }

}
